public class L108 {

    class Solution {
        public TreeNode sortedArrayToBST(int[] nums) {
            int right = nums.length - 1;
            int left = 0;

            TreeNode root = sortedArrayToBST(nums, left, right);
            return root;

        }

        private TreeNode sortedArrayToBST(int[] nums, int left, int right) {
            if (left > right) {
                return null;
            }
            int mid = left + (right - left) / 2;
            TreeNode treeNode = new TreeNode(nums[mid]);

            treeNode.left = sortedArrayToBST(nums, left, mid - 1);
            treeNode.right = sortedArrayToBST(nums, mid + 1, right);
            return treeNode;
        }
    }
}
